﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ProjectManageSystemApi.Models;
using ProjectManageSystemApi.Models.ProjectItemPriceRecordModel;
using ProjectManageSystemApi.Services;
using ProjectManageSystemApi.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ProjectManageSystemApi.Controllers
{
    [Authorize]
    [Route("api/[controller]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = Grouping.GroupName_v1)]
    public class ProjectItemPriceRecordController
    {
        readonly IProjectItemPriceRecordServices _priceRecord;
        public ProjectItemPriceRecordController(IProjectItemPriceRecordServices priceRecord) 
        {
            _priceRecord = priceRecord;
        }

        [HttpPost, Route("Get")]
        public ApiResult Query(PageBo<ProjectItemPriceRecordParams> pageBo) 
        {
            if (pageBo == null || pageBo.Param == null || pageBo.Param.ItemId <= 0) 
            {
                return ApiResultStatus.Fail(ApiResultCodes.OPERATION_FAILED);
            }
            if (pageBo.Page <= 0) 
            {
                pageBo.Page = 1;
            }
            if (pageBo.Size <= 0)
            {
                pageBo.Size = 10;
            }
            return ApiResultStatus.Success(_priceRecord.Get(pageBo));
        }

    }
}
